<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/reimupage/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/reimupage/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/reimupage/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/reimupage/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/reimupage/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/reimupage/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/reimupage/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Array,JavaScript," />










<meta name="description" content="Array对象 笔记 前言本系列为学习过程中知识的整理，学习笔记，资料均来源于网络 正文 一、Array构造函数Array是JavaScript的原生对象，同时也是一个构造函数，可以生成新数组。不同的参数，Array的行为也不同： 1.无参数 返回空数组1var arr = new Array();  //[] 2.单个正整数参数 表示数组长度12var arr = new Array(5);">
<meta name="keywords" content="Array,JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="Array对象 笔记">
<meta property="og:url" content="http://hatsunem1ku.gitee.io/reimupage/2018/04/29/Array对象/index.html">
<meta property="og:site_name" content="Reimu&#39;Blog">
<meta property="og:description" content="Array对象 笔记 前言本系列为学习过程中知识的整理，学习笔记，资料均来源于网络 正文 一、Array构造函数Array是JavaScript的原生对象，同时也是一个构造函数，可以生成新数组。不同的参数，Array的行为也不同： 1.无参数 返回空数组1var arr = new Array();  //[] 2.单个正整数参数 表示数组长度12var arr = new Array(5);">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-04-30T08:51:50.909Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Array对象 笔记">
<meta name="twitter:description" content="Array对象 笔记 前言本系列为学习过程中知识的整理，学习笔记，资料均来源于网络 正文 一、Array构造函数Array是JavaScript的原生对象，同时也是一个构造函数，可以生成新数组。不同的参数，Array的行为也不同： 1.无参数 返回空数组1var arr = new Array();  //[] 2.单个正整数参数 表示数组长度12var arr = new Array(5);">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/reimupage/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://hatsunem1ku.gitee.io/reimupage/2018/04/29/Array对象/"/>





  <title>Array对象 笔记 | Reimu'Blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/reimupage/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Reimu'Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">求知若饥 虚心若愚</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/reimupage/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/reimupage/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/reimupage/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/reimupage/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/reimupage/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hatsunem1ku.gitee.io/reimupage/reimupage/2018/04/29/Array对象/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Reimu">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/reimupage/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Reimu'Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Array对象 笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-04-29T17:08:38+08:00">
                2018-04-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/reimupage/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Array对象-笔记"><a href="#Array对象-笔记" class="headerlink" title="Array对象 笔记"></a>Array对象 笔记</h1><hr>
<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>本系列为学习过程中知识的整理，学习笔记，资料均来源于网络</p>
<h1 id="正文"><a href="#正文" class="headerlink" title="正文"></a>正文</h1><hr>
<h2 id="一、Array构造函数"><a href="#一、Array构造函数" class="headerlink" title="一、Array构造函数"></a>一、Array构造函数</h2><p>Array是JavaScript的原生对象，同时也是一个构造函数，可以生成新数组。不同的参数，Array的行为也不同：</p>
<h3 id="1-无参数-返回空数组"><a href="#1-无参数-返回空数组" class="headerlink" title="1.无参数 返回空数组"></a>1.无参数 返回空数组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>();  <span class="comment">//[]</span></span><br></pre></td></tr></table></figure>
<h3 id="2-单个正整数参数-表示数组长度"><a href="#2-单个正整数参数-表示数组长度" class="headerlink" title="2.单个正整数参数 表示数组长度"></a>2.单个正整数参数 表示数组长度</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">5</span>);  <span class="comment">//[empty × 5]</span></span><br><span class="line"><span class="keyword">var</span> arr1 = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1.0</span>);  <span class="comment">//[empty]</span></span><br></pre></td></tr></table></figure>
<h3 id="3-非正整数参数-报错"><a href="#3-非正整数参数-报错" class="headerlink" title="3.非正整数参数 报错"></a>3.非正整数参数 报错</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1.1</span>);  <span class="comment">//Uncaught RangeError: Invalid array length</span></span><br><span class="line"><span class="keyword">var</span> arr1 = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">-1</span>);  <span class="comment">// Uncaught RangeError: Invalid array length</span></span><br></pre></td></tr></table></figure>
<h3 id="4-单个非数值-该参数为新数组成员"><a href="#4-单个非数值-该参数为新数组成员" class="headerlink" title="4.单个非数值 该参数为新数组成员"></a>4.单个非数值 该参数为新数组成员</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="literal">false</span>);  <span class="comment">// [false]</span></span><br><span class="line"><span class="keyword">var</span> arr1 = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="string">'abc'</span>);  <span class="comment">//  ["abc"]</span></span><br><span class="line"><span class="keyword">var</span> arr2 = <span class="keyword">new</span> <span class="built_in">Array</span>([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]); <span class="comment">// [Array(3)]</span></span><br></pre></td></tr></table></figure>
<h3 id="5-多参数时，所有参数都是新数组成员"><a href="#5-多参数时，所有参数都是新数组成员" class="headerlink" title="5.多参数时，所有参数都是新数组成员"></a>5.多参数时，所有参数都是新数组成员</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>);  <span class="comment">// [1, 2, 3, 4]</span></span><br><span class="line"><span class="keyword">var</span> arr1 = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>);  <span class="comment">//  ["a", "b", "c"]</span></span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th>参数种类</th>
<th style="text-align:right">例子</th>
<th style="text-align:center">行为</th>
</tr>
</thead>
<tbody>
<tr>
<td>无参数</td>
<td style="text-align:right">Array()</td>
<td style="text-align:center">空数组</td>
</tr>
<tr>
<td>单个正整数</td>
<td style="text-align:right">Array(2)</td>
<td style="text-align:center">表示返回新数组的长度</td>
</tr>
<tr>
<td>非正整数</td>
<td style="text-align:right">Array(-1)</td>
<td style="text-align:center">报错</td>
</tr>
<tr>
<td>单个非数组</td>
<td style="text-align:right">Array(true)</td>
<td style="text-align:center">[true]</td>
</tr>
<tr>
<td>多参数</td>
<td style="text-align:right">Array(1,2,3,4)</td>
<td style="text-align:center">[1,2,3,4]</td>
</tr>
</tbody>
</table>
<h2 id="二、Array对象属性"><a href="#二、Array对象属性" class="headerlink" title="二、Array对象属性"></a>二、Array对象属性</h2><h3 id="1-Array-isArray"><a href="#1-Array-isArray" class="headerlink" title="1. Array.isArray()"></a>1. Array.isArray()</h3><p>用于判断一个对象是否为数组，返回true或false<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line"><span class="keyword">typeof</span> arr;   <span class="comment">//"object"</span></span><br><span class="line"><span class="built_in">Array</span>.isArray(arr);  <span class="comment">//true</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="2-valueOf-，toString"><a href="#2-valueOf-，toString" class="headerlink" title="2. valueOf()，toString()"></a>2. valueOf()，toString()</h3><p>valueOf()：返回数组对象的原始值<br>toString()：把数组转换为字符串，并返回结果<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line">arr.valueOf();  <span class="comment">// [1, 2, 3]</span></span><br><span class="line">arr.toString(); <span class="comment">// "1,2,3"</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="3-push-，pop"><a href="#3-push-，pop" class="headerlink" title="3. push()，pop()"></a>3. push()，pop()</h3><p>push()：向数组的末尾添加一个或更多元素，并返回新的长度 <strong>会改变原数组</strong><br>pop()：删除数组的最后一个元素并返回该元素 <strong>会改变原数组</strong><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line">arr.push(<span class="string">"a"</span>); <span class="comment">//4</span></span><br><span class="line">arr <span class="comment">//[1, 2, 3, "a"]</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line">arr.pop(); <span class="comment">//3</span></span><br><span class="line">arr <span class="comment">// [1, 2]</span></span><br></pre></td></tr></table></figure>
<p>push和pop结合使用，构成<strong>后进先出的栈结构</strong></p>
<hr>
<h3 id="4-shift-，unshift"><a href="#4-shift-，unshift" class="headerlink" title="4. shift()，unshift()"></a>4. shift()，unshift()</h3><p>shift()：删除并返回数组的第一个元素 <strong>会改变原数组</strong><br>unshift()：向数组的开头添加一个或更多元素，并返回新的长度 <strong>会改变原数组</strong><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>];</span><br><span class="line">arr.shift();  <span class="comment">// 1</span></span><br><span class="line">arr  <span class="comment">// [2, 3, 4]</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">"a"</span>,<span class="string">"b"</span>,<span class="string">"c"</span>];</span><br><span class="line">arr.unshift(<span class="number">1</span>); <span class="comment">//  4</span></span><br><span class="line">arr  <span class="comment">//  [1, "a", "b", "c"]</span></span><br></pre></td></tr></table></figure>
<p>push和shift结合使用，就构成了<strong>先进先出的队列结构</strong></p>
<hr>
<h3 id="5-slice-，splice"><a href="#5-slice-，splice" class="headerlink" title="5. slice()，splice()"></a>5. slice()，splice()</h3><p>slice()：选取数组的一部分，并返回一个新数组 <strong>原数组不变</strong><br>splice()：从数组中删除或添加元素，返回删除的元素 <strong>会改变原数组</strong></p>
<hr>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">arr.slice(start,end);</span><br></pre></td></tr></table></figure>
<p>第一个参数为起始位置<strong>从0开始</strong>，第二个参数为终止位置<strong>该位置的元素不包括在内</strong>，如果省略第二个元素，则一直提取到原数组末尾；如果第二个元素大于数组长度，也会一直提取到原数组末尾。</p>
<p>如果第一个参数大于等于数组长度，或者第二个参数小于第一个参数，则返回空数组<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>];</span><br><span class="line">arr.slice(<span class="number">0</span>); <span class="comment">//  [1, 2, 3, 4, 5, 6]</span></span><br><span class="line">arr.slice(<span class="number">1</span>); <span class="comment">//  [2, 3, 4, 5, 6]</span></span><br><span class="line">arr.slice(<span class="number">1</span>,<span class="number">6</span>); <span class="comment">//  [2, 3, 4, 5, 6]</span></span><br><span class="line">arr.slice(); <span class="comment">//  [1, 2, 3, 4, 5, 6]  复制一个数组</span></span><br><span class="line"></span><br><span class="line">arr.slice(<span class="number">3</span>,<span class="number">2</span>); <span class="comment">// []</span></span><br></pre></td></tr></table></figure></p>
<p>如果参数为负数，则表示倒数计算的位置<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>];</span><br><span class="line">arr.slice(<span class="number">-1</span>); <span class="comment">//  [6]  -1表示倒数第一的位置</span></span><br><span class="line">arr.slice(<span class="number">-2</span>,<span class="number">-1</span>); <span class="comment">// [5]  -2表示倒数第二的位置</span></span><br><span class="line"></span><br><span class="line">arr.slice(<span class="number">-1</span>,<span class="number">-2</span>);  <span class="comment">// []</span></span><br></pre></td></tr></table></figure></p>
<hr>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">array.splice(start,count,item1,.....,itemX);</span><br></pre></td></tr></table></figure>
<p>第一个参数是删除的起始位置<strong>从0开始</strong>，第二个参数是被删除的元素个数。如果后面还有更多的参数，则表示要被插入数组的新元素。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];</span><br><span class="line">arr.splice(<span class="number">4</span>, <span class="number">2</span>);  <span class="comment">//  ["e", "f"]</span></span><br><span class="line">arr  <span class="comment">//  ["a", "b", "c", "d"]</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];</span><br><span class="line">arr.splice(<span class="number">4</span>, <span class="number">2</span>, <span class="string">"g"</span>, <span class="string">"h"</span>, <span class="number">1</span>, <span class="number">2</span>);  <span class="comment">//  ["e", "f"]</span></span><br><span class="line">arr  <span class="comment">//  ["a", "b", "c", "d", "g", "h", 1, 2]</span></span><br></pre></td></tr></table></figure>
<p>起始位置如果是负数，就表示从倒数位置开始删除<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];</span><br><span class="line">arr.splice(<span class="number">-3</span>,<span class="number">2</span>);  <span class="comment">//   ["d", "e"]</span></span><br></pre></td></tr></table></figure></p>
<p>如果只是单纯地插入元素，splice方法的第二个参数可以设为0。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];</span><br><span class="line">arr.splice(<span class="number">1</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">3</span>); <span class="comment">// []</span></span><br><span class="line">arr  <span class="comment">// ["a", 2, 3, "b", "c", "d", "e", "f"]</span></span><br></pre></td></tr></table></figure></p>
<p>如果只提供一个参数，等同于将原数组在指定位置拆分成两个数组。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];</span><br><span class="line">arr.splice(<span class="number">4</span>); <span class="comment">// ["e", "f"]</span></span><br><span class="line">arr  <span class="comment">//  ["a", "b", "c", "d"]</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="6-join"><a href="#6-join" class="headerlink" title="6. join()"></a>6. join()</h3><p>把数组中的所有元素转换为一个字符串,如果不提供参数，默认用逗号分隔。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</span><br><span class="line">arr.join(); <span class="comment">//  "1,2,3,4,5"</span></span><br><span class="line">arr.join(<span class="string">' '</span>);  <span class="comment">//  "1 2 3 4 5"</span></span><br><span class="line">arr.join(<span class="string">'|'</span>); <span class="comment">//  "1|2|3|4|5"</span></span><br><span class="line">arr.join(<span class="string">'and'</span>);  <span class="comment">//  "1and2and3and4and5"</span></span><br></pre></td></tr></table></figure></p>
<p>如果数组成员是undefined或null或空位，会被转成空字符串。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[<span class="literal">undefined</span>, <span class="literal">null</span>].join(<span class="string">'#'</span>)  <span class="comment">// '#'</span></span><br><span class="line">[<span class="string">'a'</span>,, <span class="string">'b'</span>].join(<span class="string">'-'</span>)  <span class="comment">// 'a--b'</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="6-concat"><a href="#6-concat" class="headerlink" title="6. concat()"></a>6. concat()</h3><p>连接两个或多个数组，将新数组的成员，添加到原数组成员的后部，然后返回一个新数组，<strong>原数组不变</strong>。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">'hello'</span>].concat([<span class="string">'world'</span>])  <span class="comment">// ["hello", "world"]</span></span><br><span class="line"></span><br><span class="line">[<span class="string">'hello'</span>].concat([<span class="string">'world'</span>], [<span class="string">'!'</span>])  <span class="comment">// ["hello", "world", "!"]</span></span><br><span class="line"></span><br><span class="line">[].concat(&#123;<span class="attr">a</span>: <span class="number">1</span>&#125;, &#123;<span class="attr">b</span>: <span class="number">2</span>&#125;)  <span class="comment">// [&#123; a: 1 &#125;, &#123; b: 2 &#125;]</span></span><br><span class="line"></span><br><span class="line">[<span class="number">2</span>].concat(&#123;<span class="attr">a</span>: <span class="number">1</span>&#125;)  <span class="comment">// [2, &#123;a: 1&#125;]</span></span><br></pre></td></tr></table></figure></p>
<p>如果数组成员包括<strong>对象引用</strong>，concat方法返回当前数组的一个<strong>浅拷贝</strong>。所谓“浅拷贝”，指的是新数组拷贝的是对象的引用。对新数组操作会对原始数组产生影响。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123; <span class="attr">a</span>: <span class="number">1</span> &#125;;</span><br><span class="line"><span class="keyword">var</span> oldArr = [obj];</span><br><span class="line"><span class="keyword">var</span> newArr = oldArr.concat();  <span class="comment">// [&#123;a:1&#125;]</span></span><br><span class="line">obj.a = <span class="number">2</span>;</span><br><span class="line">newArr[<span class="number">0</span>].a  <span class="comment">// 2</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="7-reverse"><a href="#7-reverse" class="headerlink" title="7. reverse()"></a>7. reverse()</h3><p>用于颠倒排列数组元素，返回改变后的数组，<strong>会改变原数组</strong><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</span><br><span class="line">arr.reverse();  <span class="comment">//  [5, 4, 3, 2, 1]</span></span><br><span class="line">arr  <span class="comment">//  [5, 4, 3, 2, 1]</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="8-sort"><a href="#8-sort" class="headerlink" title="8. sort()"></a>8. sort()</h3><p>对数组成员进行排序，默认是按照字典顺序排序。排序后，<strong>会改变原数组</strong><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">"Banana"</span>, <span class="string">"Orange"</span>, <span class="string">"Apple"</span>, <span class="string">"Mango"</span>];</span><br><span class="line">arr.sort(); <span class="comment">//  ["Apple", "Banana", "Mango", "Orange"]</span></span><br><span class="line">arr  <span class="comment">//   ["Apple", "Banana", "Mango", "Orange"]</span></span><br></pre></td></tr></table></figure></p>
<p>sort的参数函数本身接受两个参数，表示进行比较的两个数组成员。如果该<strong>函数的返回值大于0</strong>，表示<strong>第一个成员排在第二个成员后面</strong>；其他情况下，都是第一个元素排在第二个元素前面<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">40</span>,<span class="number">100</span>,<span class="number">1</span>,<span class="number">5</span>,<span class="number">25</span>,<span class="number">10</span>];</span><br><span class="line">arr.sort(<span class="function"><span class="keyword">function</span>(<span class="params">a,b</span>)</span>&#123;<span class="keyword">return</span> a-b&#125;);</span><br><span class="line"><span class="comment">//  [1, 5, 10, 25, 40, 100]</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">40</span>,<span class="number">100</span>,<span class="number">1</span>,<span class="number">5</span>,<span class="number">25</span>,<span class="number">10</span>];</span><br><span class="line">arr.sort(<span class="function"><span class="keyword">function</span>(<span class="params">a,b</span>)</span>&#123;<span class="keyword">return</span> b-a&#125;);</span><br><span class="line"><span class="comment">//  [100, 40, 25, 10, 5, 1]</span></span><br></pre></td></tr></table></figure>
<hr>
<h3 id="9-map"><a href="#9-map" class="headerlink" title="9. map()"></a>9. map()</h3><p>创建一个新数组，其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>];</span><br><span class="line">num.map(<span class="function"><span class="keyword">function</span>(<span class="params">n</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> n+<span class="number">1</span>;</span><br><span class="line">&#125;);  <span class="comment">//  [2, 3, 4, 5]</span></span><br><span class="line">num  <span class="comment">//  [1, 2, 3, 4]</span></span><br></pre></td></tr></table></figure></p>
<p>语法：array.map(function(currentValue,index,arr), thisValue)<br>| 参数 | 描述 |<br>| —– | —– |<br>| currentValue | 必须，当前元素的值 |<br>| index | 可选，当前元素的索引值 |<br>| arr | 可选，当前元素属于的数组对象 |<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].map(<span class="function"><span class="keyword">function</span>(<span class="params">elem, index, arr</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> elem * index;</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">//  [0, 2, 6]</span></span><br></pre></td></tr></table></figure></p>
<p>elem为当前成员的值，index为当前成员的位置，arr为原数组（[1, 2, 3]）。<br>map方法还可以接受第二个参数，用来绑定回调函数内部的this变量。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'a'</span>,<span class="string">'b'</span>,<span class="string">'c'</span>];</span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>].map(<span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>[e]&#125;,arr);</span><br><span class="line"><span class="comment">//  ["b", "c"]  回调函数内部的this对象，指向arr数组</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="10-forEach"><a href="#10-forEach" class="headerlink" title="10. forEach()"></a>10. forEach()</h3><p>用于调用数组的每个元素，并将元素传递给回调函数。<br>forEach方法和map类似，但是，不返回值，只用来操作数据。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">log</span>(<span class="params">e,i,arr</span>)</span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'['</span>+i+<span class="string">']='</span> + e);</span><br><span class="line">&#125;</span><br><span class="line">[<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>].forEach(log);</span><br><span class="line"><span class="comment">// [0]=2</span></span><br><span class="line"><span class="comment">// [1]=3</span></span><br><span class="line"><span class="comment">// [2]=4</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> out = [];</span><br><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>].forEach(<span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;<span class="keyword">this</span>.push(e*e)&#125;,out);</span><br><span class="line">out <span class="comment">//  [1,4,9]</span></span><br></pre></td></tr></table></figure>
<p>forEach，map方法不会跳过undefined和null，但会跳过空位。</p>
<hr>
<h3 id="11-filter"><a href="#11-filter" class="headerlink" title="11. filter()"></a>11. filter()</h3><p>用于过滤数组成员，创建一个新的数组，新数组中的元素是通过检查指定数组中符合条件的所有元素。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>].filter(<span class="function"><span class="keyword">function</span> (<span class="params">elem</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> (elem &gt; <span class="number">3</span>);</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">//   [4, 5]</span></span><br></pre></td></tr></table></figure></p>
<p>语法：array.filter(function(currentValue,index,arr), thisValue)<br>filter方法的参数函数可以接受三个参数：当前成员，当前位置和整个数组。<br>filter方法还可以接受第二个参数，用来绑定参数函数内部的this变量。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123; <span class="attr">MAX</span>:<span class="number">3</span> &#125;;</span><br><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">5</span>,<span class="number">6</span>];</span><br><span class="line">arr.filter(<span class="function"><span class="keyword">function</span>(<span class="params">item</span>)</span>&#123;</span><br><span class="line">   <span class="keyword">if</span>(item &gt; <span class="keyword">this</span>.MAX)</span><br><span class="line">   <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;,obj);  <span class="comment">//  [4, 5, 6]</span></span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="12-some-，every"><a href="#12-some-，every" class="headerlink" title="12. some()，every()"></a>12. some()，every()</h3><p>some() 方法用于检测数组中的元素是否满足指定条件（函数提供）。<br>every() 方法用于检测数组所有元素是否都符合指定条件（通过函数提供）。</p>
<p>some方法是<strong>只要一个成员</strong>的返回值是true，则整个some方法的返回值就是true，否则返回false。<br>every方法是<strong>所有成员</strong>的返回值都是true，整个every方法才返回true，否则返回false。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</span><br><span class="line">arr.some(<span class="function"><span class="keyword">function</span>(<span class="params">e,i,arr</span>)</span>&#123;<span class="keyword">return</span> e&gt;= <span class="number">3</span>&#125;);</span><br><span class="line"><span class="comment">// true</span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</span><br><span class="line">arr.every(<span class="function"><span class="keyword">function</span>(<span class="params">e,i,arr</span>)</span>&#123;<span class="keyword">return</span> e &gt;= <span class="number">3</span>&#125;);</span><br><span class="line"><span class="comment">//  false</span></span><br></pre></td></tr></table></figure>
<hr>
<h3 id="13-reduce-，reduceRight"><a href="#13-reduce-，reduceRight" class="headerlink" title="13. reduce()，reduceRight()"></a>13. reduce()，reduceRight()</h3><p>reduce()：将数组元素计算为一个值（从左到右）<br>reduceRight()：将数组元素计算为一个值（从右到左）</p>
<p>array.reduce(function(total, currentValue, currentIndex, arr), initialValue)</p>
<blockquote>
<ul>
<li>total        : 必需，初始值，或者计算结束后的返回值</li>
<li>currentValue ：必需，当前元素</li>
<li>currentIndex ：可选，当前元素的索引</li>
<li>arr          ：可选，当前元素所属的数组对象</li>
<li>initialValue ：可选。传递给函数的初始值</li>
</ul>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>].reduce(<span class="function"><span class="keyword">function</span>(<span class="params">a,b</span>)</span>&#123;</span><br><span class="line">   <span class="built_in">console</span>.log(a,b);</span><br><span class="line">   <span class="keyword">return</span> a + b;</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">// 1 2</span></span><br><span class="line"><span class="comment">// 3 3</span></span><br><span class="line"><span class="comment">// 6 4</span></span><br><span class="line"><span class="comment">// 10 5</span></span><br><span class="line"><span class="comment">// 15</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>].reduce(<span class="function"><span class="keyword">function</span> (<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> a + b;</span><br><span class="line">&#125;, <span class="number">10</span>);</span><br><span class="line"><span class="comment">//  25</span></span><br></pre></td></tr></table></figure>
<hr>
<h3 id="14-indexOf-，lastIndexOf"><a href="#14-indexOf-，lastIndexOf" class="headerlink" title="14. indexOf()，lastIndexOf()"></a>14. indexOf()，lastIndexOf()</h3><p>indexOf() 方法可返回某个指定的字符串值在字符串中<strong>首次</strong>出现的位置，没有出现则返回-1。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = [<span class="string">'a'</span>,<span class="string">'b'</span>,<span class="string">'c'</span>];</span><br><span class="line">a.indexOf(<span class="string">'b'</span>) <span class="comment">//  1</span></span><br><span class="line">a.indexOf(<span class="string">'y'</span>) <span class="comment">//  -1</span></span><br></pre></td></tr></table></figure></p>
<p>语法：array.indexOf(item,start)</p>
<blockquote>
<ul>
<li>item  必须，查找的元素</li>
<li>start 可选的值，从0到stringObject.length-1 搜索的开始位置<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>].indexOf(<span class="string">'a'</span>, <span class="number">1</span>) <span class="comment">// -1</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</blockquote>
<p>lastIndexOf方法返回给定元素在数组中<strong>最后</strong>一次出现的位置，如果没有出现则返回-1。</p>
<hr>
<h2 id="三、参考链接"><a href="#三、参考链接" class="headerlink" title="三、参考链接"></a>三、参考链接</h2><p><a href="http://javascript.ruanyifeng.com/" target="_blank" rel="noopener">JavaScript 标准参考教程（alpha）</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/reimupage/tags/Array/" rel="tag"># Array</a>
          
            <a href="/reimupage/tags/JavaScript/" rel="tag"># JavaScript</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/reimupage/2018/05/06/RegExp对象/" rel="prev" title="正则表达式 笔记">
                正则表达式 笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/reimupage/images/avatar.gif"
                alt="Reimu" />
            
              <p class="site-author-name" itemprop="name">Reimu</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/reimupage/archives/">
              
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">分类</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Array对象-笔记"><span class="nav-number">1.</span> <span class="nav-text">Array对象 笔记</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">2.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#正文"><span class="nav-number">3.</span> <span class="nav-text">正文</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、Array构造函数"><span class="nav-number">3.1.</span> <span class="nav-text">一、Array构造函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-无参数-返回空数组"><span class="nav-number">3.1.1.</span> <span class="nav-text">1.无参数 返回空数组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-单个正整数参数-表示数组长度"><span class="nav-number">3.1.2.</span> <span class="nav-text">2.单个正整数参数 表示数组长度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-非正整数参数-报错"><span class="nav-number">3.1.3.</span> <span class="nav-text">3.非正整数参数 报错</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-单个非数值-该参数为新数组成员"><span class="nav-number">3.1.4.</span> <span class="nav-text">4.单个非数值 该参数为新数组成员</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-多参数时，所有参数都是新数组成员"><span class="nav-number">3.1.5.</span> <span class="nav-text">5.多参数时，所有参数都是新数组成员</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、Array对象属性"><span class="nav-number">3.2.</span> <span class="nav-text">二、Array对象属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-Array-isArray"><span class="nav-number">3.2.1.</span> <span class="nav-text">1. Array.isArray()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-valueOf-，toString"><span class="nav-number">3.2.2.</span> <span class="nav-text">2. valueOf()，toString()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-push-，pop"><span class="nav-number">3.2.3.</span> <span class="nav-text">3. push()，pop()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-shift-，unshift"><span class="nav-number">3.2.4.</span> <span class="nav-text">4. shift()，unshift()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-slice-，splice"><span class="nav-number">3.2.5.</span> <span class="nav-text">5. slice()，splice()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-join"><span class="nav-number">3.2.6.</span> <span class="nav-text">6. join()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-concat"><span class="nav-number">3.2.7.</span> <span class="nav-text">6. concat()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-reverse"><span class="nav-number">3.2.8.</span> <span class="nav-text">7. reverse()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-sort"><span class="nav-number">3.2.9.</span> <span class="nav-text">8. sort()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-map"><span class="nav-number">3.2.10.</span> <span class="nav-text">9. map()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-forEach"><span class="nav-number">3.2.11.</span> <span class="nav-text">10. forEach()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-filter"><span class="nav-number">3.2.12.</span> <span class="nav-text">11. filter()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-some-，every"><span class="nav-number">3.2.13.</span> <span class="nav-text">12. some()，every()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#13-reduce-，reduceRight"><span class="nav-number">3.2.14.</span> <span class="nav-text">13. reduce()，reduceRight()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#14-indexOf-，lastIndexOf"><span class="nav-number">3.2.15.</span> <span class="nav-text">14. indexOf()，lastIndexOf()</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、参考链接"><span class="nav-number">3.3.</span> <span class="nav-text">三、参考链接</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Reimu</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/reimupage/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/reimupage/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/reimupage/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/reimupage/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/reimupage/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/reimupage/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/reimupage/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/reimupage/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/reimupage/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/reimupage/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/reimupage/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/reimupage/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/reimupage/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/reimupage/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
